import { Body, Controller, Delete, Get, Param, Patch, Post, Query } from "@nestjs/common";
import { ApiBearerAuth, ApiOperation, ApiTags } from "@nestjs/swagger";

import AjaxResult from "@/core/utils/AjaxResult";

import { CreateFileDirDto } from "../dto/create-file-dir.dto";
import { QueryFileDirDto } from "../dto/query-file-dir.dto";
import { UpdateFileDirDto } from "../dto/update-file-dir.dto";
import { FileDirService } from "../service/file-dir.service";

@ApiTags("文件夹管理")
@ApiBearerAuth()
@Controller("/admin/file-dir")
export class FileDirAdminController {
    constructor(private readonly fileDirService: FileDirService) {}

    @ApiOperation({ summary: "目录添加" })
    @Post("/add")
    async create(@Body() createFileDirDto: CreateFileDirDto) {
        return AjaxResult.success(await this.fileDirService.create(createFileDirDto));
    }

    @ApiOperation({ summary: "目录分页列表" })
    @Get("/page")
    async findListPage(@Query() query: QueryFileDirDto) {
        return AjaxResult.success(await this.fileDirService.findListPage(query));
    }

    @ApiOperation({ summary: "目录列表" })
    @Get("/all")
    async findAll() {
        return AjaxResult.success(await this.fileDirService.findAll());
    }

    @ApiOperation({ summary: "目录树形结构" })
    @Get("/tree")
    async getTreeFileDir(@Query() query: QueryFileDirDto) {
        return AjaxResult.success(await this.fileDirService.getTreeFileDir(query));
    }

    @ApiOperation({ summary: "目录详情" })
    @Get("/detail/:id")
    async findOne(@Param("id") id: string) {
        return AjaxResult.success(await this.fileDirService.findOne(+id));
    }

    @ApiOperation({ summary: "目录编辑" })
    @Patch("/edit/:id")
    async update(@Param("id") id: string, @Body() updateFileDirDto: UpdateFileDirDto) {
        return AjaxResult.success(await this.fileDirService.update(+id, updateFileDirDto));
    }

    @ApiOperation({ summary: "目录删除" })
    @Delete("/delete/:id")
    async remove(@Param("id") id: string) {
        return AjaxResult.success(await this.fileDirService.remove(+id));
    }
}
